package com.golxen.framework.common.server.agent.cmd;


import com.golxen.framework.AgentProtocol;
import com.golxen.framework.PBPacket.PBPacket;
import com.golxen.framework.common.server.agent.AgentPlayer;
import com.golxen.framework.common.server.agent.AgentPlayerMgr;
import com.golxen.framework.common.server.game.cmd.Cmd;
import com.golxen.framework.common.server.game.cmd.Command;
import io.netty.channel.ChannelHandlerContext;

@Cmd(code = AgentProtocol.A_PLAYER_OFFLINE, desc = "心跳检测用户下线,与强制踢玩家下线区分（改状态）")
public class PlayerOfflineCmd implements Command {
    @Override
    public Command.Tuple execute(ChannelHandlerContext ctx, PBPacket packet) throws Exception {
        long userId = packet.getPlayerId();
        AgentPlayer player = AgentPlayerMgr.getOnlineUser(userId);
        if (player != null) {
            AgentPlayerMgr.removeOnline(userId, player.getChannel(), false);
        } else {
            AgentPlayerMgr.removeOnline(userId, null, false);
        }
        
        return new Tuple(null, null);
    }
}
